package racetrack

class AdminFilters {

	def filters = {
		//filters want actions as a regex
		adminOnly(controller:'*', action:"(create|edit|update|delete|save)"){
			before = {
				if (!session?.user?.admin){
					flash.message = "We don't serve your kind here."
					redirect(controller:"race", action:"list")
					return false
				}
			}
		}

		all(controller:'*', action:"(create|edit|delete|update|save|list|show)") {
			before = {
				if (!session?.user){
					redirect(controller:"user", action:"login")
					return false
				}
			}
			after = {

			}
			afterView = {

			}
		}
	}

}
